/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine - DirectX 10 Plugin
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#define DIRECTX_10_PLUGIN_SOURCE 1

#include "DirectX_10_ImageFileReader.h"
#include "DirectX_10_Texture.h"

#include <algorithm>
#include <string>

using namespace Omen;

// <summary>Returns true if this reader can read the given file</summary>
bool DirectX_10_ImageReader::canRead( const std::wstring& filename )
{
    bool bCanRead = false;

    std::wstring ext = filename;
    if( ext.find( L"." ) != std::wstring::npos )
    {
        ext = ext.substr(ext.find_last_of( L"." )+1);
        std::transform(ext.begin(), ext.end(),ext.begin(), ::toupper);
        // If the file extension is one of the list that D3DX10_IMAGE_FILE_FORMAT defines,
        // We might be lucky to read this file.
        if( ext == L"BMP" ||
            ext == L"JPG" ||
            ext == L"JPEG" ||
            ext == L"PNG" ||
            ext == L"DDS" ||
            ext == L"TIFF" ||
            ext == L"TGA" ||
            ext == L"GIF" ||
            ext == L"WMP" )
            bCanRead = true;
            
    }

    return bCanRead;    
}

ITexture* DirectX_10_ImageReader::createTexture( const std::wstring& filename )
{
    return new DirectX_10_Texture(filename);
}